package com.example.security.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.example.security.config.DBUserDetailsManager;
import com.example.security.config.DBUserDetailsManager;
import com.example.security.domain.User;
import com.example.security.mapper.UserMapper;
import com.example.security.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: DongGuoZhen
 * @Date: 2025/04/25/10:03
 * @Description:
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private DBUserDetailsManager dbUserDetailsManager;

    @Override
    public void saveUserDetails(User user) {

        UserDetails userDetails = org.springframework.security.core.userdetails.User
                .withDefaultPasswordEncoder() // 使用默认的密码加密方案
                .username(user.getUsername()) //自定义用户名
                .password(user.getPassword()) //自定义密码  密码会自动加密
                .build();
        dbUserDetailsManager.createUser(userDetails);

    }
}
